package com.woniuxy.food.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.food.client.foodtypeclient.FoodTypeQueryClient;
import com.woniuxy.food.client.param.SearchFoodTypeByConditionParam;
import com.woniuxy.food.client.result.FoodTypeClientDto;
import com.woniuxy.food.service.FoodTypeService;
import com.woniuxy.food.service.servicedto.FoodTypeServiceDto;
import com.woniuxy.food.service.serviceparam.SearchFoodTypeByConditionServiceParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import java.util.List;

@RestController
@Slf4j
public class FoodTypeQueryClientApiImpl implements FoodTypeQueryClient {
    @Autowired
    private FoodTypeService foodTypeService;

    @Override
    @Log("根据条件查询菜品类型")
    public Result<List<FoodTypeClientDto>> searchFoodTypeByCondition(SearchFoodTypeByConditionParam param) {
        SearchFoodTypeByConditionServiceParam searchFoodTypeByConditionServiceParam = BeanUtil.toBean(param, SearchFoodTypeByConditionServiceParam.class);
        List<FoodTypeServiceDto> foodTypeServiceDtos =foodTypeService.searchFoodTypeByCondition(searchFoodTypeByConditionServiceParam);
        List<FoodTypeClientDto> foodTypeClientDtos = BeanUtil.copyToList(foodTypeServiceDtos, FoodTypeClientDto.class);
        return Result.success(foodTypeClientDtos);
    }
}
